//
//  HeartListViewController.m
//  你的温实初
//
//  Created by lanou on 16/7/16.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "HeartListViewController.h"

@interface HeartListViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webview;

@end

@implementation HeartListViewController

- (UIWebView *)webview {
    if (!_webview) {
        _webview = [[UIWebView alloc] initWithFrame:self.view.frame];
        _webview.scrollView.bounces = NO;
        _webview.scrollView.bouncesZoom= NO;
        _webview.delegate = self;
    }
    return _webview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.webview];
    
    // 请求数据
    [RequestManager fetchDataWithUrl:[NSString stringWithFormat:@"http://www.popodd.com/shopxx/app/jk_article!knowledgeDetail.action?id=%@", self.ID] Parameter:@{} Method:@"POST" Compelet:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        [self.webview loadHTMLString:bigDic[@"datasource"][@"content"] baseURL:nil];
    } updateUI:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}

#pragma mark ---------webview---------

- (void)webViewDidStartLoad:(UIWebView *)webView {
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *js = @"function imgAutoFit() { \
    var imgs = document.getElementsByTagName('img'); \
    for (var i = 0; i < imgs.length; ++i) {\
    var img = imgs[i];   \
    img.style.maxWidth = %f;   \
    } \
    }";
    //    NSString *js2 = @"var s= document.getElementsByTagName("img");
    //    for(var i = 0; i < s.length; i++){
    //        s[i].remove();
    //
    //    }"
    NSString *js2 = @"var s= document.getElementsByTagName('img'); \
    for(var i = 0); i < s.length; i++) {\
    s[i].remove(); \
    }";
    
    js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
    
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:js2];
    [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
